package com.example.servlet;

import com.alibaba.fastjson.JSON;
import com.example.model.Carousel;
import com.example.service.impl.CarouselServiceImpl;
import com.example.vo.ResponseData;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 获取首页的轮播图
 */
@WebServlet("/HomeServlet/queryAll")
public class QueryCarouselServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/json;charset=utf-8");
        List<Carousel> imgList = new CarouselServiceImpl().getAll();
        resp.getWriter().println(JSON.toJSONString(ResponseData.ok(imgList)));
    }
}
